# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>
# Contributor: Biswapriyo Nath <nathbappai@gmail.com>

_realname=spirv-headers
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.3.1
_realver="1.5.3.reservations1"
pkgrel=1
pkgdesc='Machine-readable files for the SPIR-V Registry (mingw-w64)'
arch=('any')
url='https://www.khronos.org/registry/spir-v/'
license=('MIT')
groups=("${MINGW_PACKAGE_PREFIX}-vulkan-devel")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/KhronosGroup/SPIRV-Headers/archive/${_realver}.tar.gz")
sha512sums=('18ebb3a4ed0eb84646460a9f0cf416d87ea6f7d9a36cabfbaa553c6620dc4f0cbc5dddb3ee072a8c7999f4a5bebfdf7b1c479b3b35cf886414bd5f67fb732db2')

prepare() {
  mv "${srcdir}/${_realname}-${_realver}" "${srcdir}/${_realname}-${pkgver}"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build ./
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build ./ --target install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/README.md ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
